<?php

/**
 * Subclass for performing query and update operations on the 'municipio' table.
 *
 * 
 *
 * @package lib.model
 */ 
class MunicipioPeer extends BaseMunicipioPeer
{
  static public function doSelectByEstado($estado)
  {
    $c= new Criteria();
    $c->add(MunicipioPeer::ID_ESTADO ,$estado);
    return  MunicipioPeer::doSelect($c);
  }
  public static function doSelectJoinAll(Criteria $c, $con = null, $join_behavior = Criteria::LEFT_JOIN)
	{
		$c = clone $c;
    if ($c->getDbName() == Propel::getDefaultDB()) {
			$c->setDbName(self::DATABASE_NAME);
		}

		MunicipioPeer::addSelectColumns($c);
		$startcol2 = (MunicipioPeer::NUM_COLUMNS - MunicipioPeer::NUM_LAZY_LOAD_COLUMNS) + 1;

		EstadoPeer::addSelectColumns($c);
		$startcol3 = $startcol2 + EstadoPeer::NUM_COLUMNS;
		
		PaisPeer::addSelectColumns($c);

		$c->addJoin(MunicipioPeer::ID_ESTADO, EstadoPeer::ID_ESTADO);
    $c->addJoin(EstadoPeer::ID_PAIS , PaisPeer::ID_PAIS );
    
		$rs = BasePeer::doSelect($c, $con);
		$results = array();

		while($rs->next()) {

			$omClass = MunicipioPeer::getOMClass();

			$cls = Propel::import($omClass);
			$obj1 = new $cls();
			$obj1->hydrate($rs);
					
			$omClass = EstadoPeer::getOMClass();

			$cls = Propel::import($omClass);
			$obj2 = new $cls();
			$obj2->hydrate($rs, $startcol2);

			$omClass = PaisPeer::getOMClass();

			$cls = Propel::import($omClass);
			$obj3 = new $cls();
			$obj3->hydrate($rs, $startcol3);

			$newObject = true;
			$newObject2 = true;
			for ($j=0, $resCount=count($results); $j < $resCount; $j++) {
				$temp_obj1 = $results[$j];
				$temp_obj2 = $temp_obj1->getEstado();
				$temp_obj3 = $temp_obj2->getPais(); 				
				if ($temp_obj3->getPrimaryKey() === $obj3->getPrimaryKey()) {
					$newObject2 = false;
					$temp_obj3->addEstado($obj2); 					
				}
				if ($temp_obj2->getPrimaryKey() === $obj2->getPrimaryKey()) {
					$newObject = false;
					$temp_obj2->addMunicipio($obj1); 					
					break;
				}
			}

			if ($newObject) {
				$obj2->initMunicipios();
				$obj2->addMunicipio($obj1);
			}
      
			if ($newObject2) {
				$obj3->initEstados();
				$obj3->addEstado($obj2);
			}
			
			
			$results[] = $obj1;
		}
		return $results;
	}
}


